import React from 'react';
import { inject, observer } from 'mobx-react';
import { WeaLeftRightLayout,WeaLocaleProvider,WeaTools} from 'ecCom';
import {Menu,Tooltip} from 'antd';
import GoalMain from './GoalMain';
import * as Util from '../../util/Util';
import GoalExport from '../goal/goalexport/GoalExport'
const { SubMenu, Item} = Menu;
const getLabel = WeaLocaleProvider.getLabel;
@inject("goalCommonStore")
@observer
export default class GoalIndex extends React.Component {
    constructor(props) {
        super(props);
        this.state ={
            cunrrentkey:"1",
            toptitle:"",
            isRight:"",
            unread:{
                createGoal:0,
                chargeGoal:0,
                participateGoal:0,
                specialGoal:0,
                shareGoal:0,
                allGoal:0,
            },
            isShowOrgGoal:false, //是否展示组织目标
        }
        this.menumap = {}
    }
    componentWillMount() {//一些初始化请求
        WeaTools.callApi('/api/workrelate/common/checkHasRigth', 'GET', {id:1}).then((data) => {
            if(data.status && data.isRight){
                this.setState({isRight:"1",isShowOrgGoal:data.isShowOrgGoal});
            }else{
                this.setState({isRight:"0",isShowOrgGoal:data.isShowOrgGoal});
            }

        })
        if (Util.getParams('condtype') && Util.getParams('condtype') != '') {
            let cunrrentkey = Util.getParams('condtype');
            let toptitle = this.getTopTitle(cunrrentkey);
            this.setState({cunrrentkey,toptitle})       
        }else{
            let { cunrrentkey } = this.state;
            let toptitle = this.getTopTitle(cunrrentkey);
            this.setState({toptitle})
        }


        // WeaTools.callApi('/api/workrelate/goal/checkNew', 'GET', {}).then((data) => {
        //     //获取未读数
        //     if(data.status){
        //         let {unread} = this.state;
        //         if(data.list.length > 0){
        //             unread.createGoal = data.list[0].count;
        //             unread.chargeGoal = data.list[1].count;
        //             unread.participateGoal = data.list[2].count;
        //             unread.specialGoal = data.list[3].count;
        //             unread.shareGoal = data.list[4].count;
        //             for(let i = 0;i < 5;i ++){
        //                 unread.allGoal += data.list[i].count;
        //             }
        //             this.setState({
        //                 unread
        //             })
        //         }
        //     }
    
        // });
    }

    componentWillReceiveProps(newProps) {
        // const { goalCommonStore:{condtype} } = this.props;
        // const { cunrrentkey } = this.state;
        // if(cunrrentkey != condtype){
        //     this.setState({cunrrentkey:condtype})
        // }
    }

    //绑定子组件的方法
    onRef = (ref) => {
        this.child = ref
    }

    handleClick = (e) => {
        // console.log(e.key)
        // console.log(e.item.props.title)
        this.setState({
            cunrrentkey: e.key,
            toptitle:e.item.props.title
          });
          this.child.onCloseSlideModal();
    }

    getTopTitle = (condtype) =>{
        let map = new Map();
        map.set("1",getLabel(18028,"我的目标"));
        map.set("2",getLabel(518141,"组织目标"));
        map.set("3",getLabel(506156,"我创建的目标"));
        map.set("4",getLabel(506157,"我参与的目标"));
        map.set("5",getLabel(506159,"分享给我的目标"));
        map.set("6",getLabel(506158,"我关注的目标"));
        map.set("8",getLabel(506156,"我创建的目标"));
        map.set("9",getLabel(506159,"分享给我的目标"));
        map.set("10",getLabel(520928,"目标导出"));
        return map.get(condtype);
    }


    render() {
        // const { goal } = this.props;
        const { cunrrentkey, toptitle, unread, isRight, isShowOrgGoal } = this.state;
        if(isRight==""){
            return <div></div>;
        }
        if(isRight=="0"){
            return Util.renderAlertPage('<span style="color:red">'+getLabel(509341,"您的系统未开启目标管理模块")+'</span>','','','',this.props.ecId || '');
        }
        let menu = isShowOrgGoal ? <Menu ecId={`${this && this.props && this.props.ecId || ''}_Menu@z2d8n3`} onClick={this.handleClick}
        style={{ width: 248 }}
        defaultOpenKeys={[cunrrentkey]}
        selectedKeys={[cunrrentkey]}
        mode="inline">
            <Item ecId={`${this && this.props && this.props.ecId || ''}_Item@tirsep`} key="1" style={{height:'30px',lineHeight:"30px"}} title={getLabel(18028,"我的目标")}><span>{getLabel(18028,"我的目标")}</span>{unread.chargeGoal == 0 ? "":<Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@q2vhuu`} title="未查看目标"><span className="workrelate-unread">{unread.chargeGoal}</span></Tooltip>}</Item>
            {/* <Item key="2" style={{height:'30px',lineHeight:"30px"}} title={getLabel(518141,"组织目标")}><span>{getLabel(518141,"组织目标")}</span></Item> */}
            <Item ecId={`${this && this.props && this.props.ecId || ''}_Item@64ba3l`} key="3" style={{height:'30px',lineHeight:"30px"}} title={getLabel(506156,"我创建的目标")}><span>{getLabel(506156,"我创建的目标")}</span>{unread.createGoal == 0 ? "":<Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@et8qgs`} title="未查看目标"><span className="workrelate-unread">{unread.createGoal}</span></Tooltip>}</Item>
            <Item ecId={`${this && this.props && this.props.ecId || ''}_Item@y52pqg`} key="4" style={{height:'30px',lineHeight:"30px"}} title={getLabel(506157,"我参与的目标")}><span>{getLabel(506157,"我参与的目标")}</span>{unread.participateGoal == 0 ? "":<Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@40lenk`} title="未查看目标"><span className="workrelate-unread">{unread.participateGoal}</span></Tooltip>}</Item>
            <Item ecId={`${this && this.props && this.props.ecId || ''}_Item@m8y9h6`} key="6" style={{height:'30px',lineHeight:"30px"}} title={getLabel(506158,"我关注的目标")}><span>{getLabel(506158,"我关注的目标")}</span>{unread.specialGoal == 0 ? "":<Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@czo0kk`} title="未查看目标"><span className="workrelate-unread">{unread.specialGoal}</span></Tooltip>}</Item>
            <Item ecId={`${this && this.props && this.props.ecId || ''}_Item@u7zlbp`} key="5" style={{height:'30px',lineHeight:"30px"}} title={getLabel(506159,"分享给我的目标")}><span>{getLabel(506159,"分享给我的目标")}</span>{unread.shareGoal == 0 ? "":<Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@yswrpt`} title="未查看目标"><span className="workrelate-unread">{unread.shareGoal}</span></Tooltip>}</Item>
            <Item ecId={`${this && this.props && this.props.ecId || ''}_Item@m3srqn`} key="0" style={{height:'30px',lineHeight:"30px"}} title={getLabel(506160,"所有目标")}><span>{getLabel(506160,"所有目标")}</span>{unread.allGoal == 0 ?  "":<Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@i8e43j`} title="未查看目标"><span className="workrelate-unread">{unread.allGoal}</span></Tooltip>}</Item>
            <Item ecId={`${this && this.props && this.props.ecId || ''}_Item@xzsi8n`} key="10" style={{height:'30px',lineHeight:"30px"}} title={getLabel(520928,"目标导出")}><span>{getLabel(520928,"目标导出")}</span>{unread.allGoal == 0 ?  "":<Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@z5kfmt`} title="未查看目标"><span className="workrelate-unread">{unread.allGoal}</span></Tooltip>}</Item>
            {isShowOrgGoal && <SubMenu ecId={`${this && this.props && this.props.ecId || ''}_SubMenu@or3ef3`}
                style={{height:'30px',lineHeight:"30px"}}
                key="sub4"
                title={
                    <span>
                        <span>{getLabel(518141,"组织目标")}</span>
                    </span>
                }
            >
                <Item ecId={`${this && this.props && this.props.ecId || ''}_Item@e3t99w`} key="2" style={{height:'30px',lineHeight:"30px"}} title={getLabel(518141,"组织目标")}><span>{getLabel(518141,"组织目标")}</span></Item>
                <Item ecId={`${this && this.props && this.props.ecId || ''}_Item@lq5wx7`} key="8" style={{height:'30px',lineHeight:"30px"}} title={getLabel(506156,"我创建的目标")}><span>{getLabel(506156,"我创建的目标")}</span>{unread.createGoal == 0 ? "":<Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@hp8mx4`} title="未查看目标"><span className="workrelate-unread">{unread.createGoal}</span></Tooltip>}</Item>
                <Item ecId={`${this && this.props && this.props.ecId || ''}_Item@knchmu`} key="9" style={{height:'30px',lineHeight:"30px"}} title={getLabel(506159,"分享给我的目标")}><span>{getLabel(506159,"分享给我的目标")}</span>{unread.shareGoal == 0 ? "":<Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@0bz1w0`} title="未查看目标"><span className="workrelate-unread">{unread.shareGoal}</span></Tooltip>}</Item>
            </SubMenu>}
            {/* <Item key="7" style={{height:'30px',lineHeight:"30px"}} title={getLabel(518141,"组织目标")}><span>{getLabel(518141,"组织目标")}</span>{unread.allGoal == 0 ?  "":<Tooltip title="未查看目标"><span className="workrelate-unread">{unread.allGoal}</span></Tooltip>}</Item> */}
        </Menu>:<Menu ecId={`${this && this.props && this.props.ecId || ''}_Menu@kgf30o`} onClick={this.handleClick}
        style={{ width: 248 }}
        defaultOpenKeys={[cunrrentkey]}
        selectedKeys={[cunrrentkey]}
        mode="inline">
            <Item ecId={`${this && this.props && this.props.ecId || ''}_Item@engt6w`} key="1" style={{height:'30px',lineHeight:"30px"}} title={getLabel(18028,"我的目标")}><span>{getLabel(18028,"我的目标")}</span>{unread.chargeGoal == 0 ? "":<Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@l0fl5b`} title="未查看目标"><span className="workrelate-unread">{unread.chargeGoal}</span></Tooltip>}</Item>
            {/* <Item key="2" style={{height:'30px',lineHeight:"30px"}} title={getLabel(518141,"组织目标")}><span>{getLabel(518141,"组织目标")}</span></Item> */}
            <Item ecId={`${this && this.props && this.props.ecId || ''}_Item@jrbun4`} key="3" style={{height:'30px',lineHeight:"30px"}} title={getLabel(506156,"我创建的目标")}><span>{getLabel(506156,"我创建的目标")}</span>{unread.createGoal == 0 ? "":<Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@p1p4hp`} title="未查看目标"><span className="workrelate-unread">{unread.createGoal}</span></Tooltip>}</Item>
            <Item ecId={`${this && this.props && this.props.ecId || ''}_Item@zktssz`} key="4" style={{height:'30px',lineHeight:"30px"}} title={getLabel(506157,"我参与的目标")}><span>{getLabel(506157,"我参与的目标")}</span>{unread.participateGoal == 0 ? "":<Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@xuj58q`} title="未查看目标"><span className="workrelate-unread">{unread.participateGoal}</span></Tooltip>}</Item>
            <Item ecId={`${this && this.props && this.props.ecId || ''}_Item@5zbcbg`} key="6" style={{height:'30px',lineHeight:"30px"}} title={getLabel(506158,"我关注的目标")}><span>{getLabel(506158,"我关注的目标")}</span>{unread.specialGoal == 0 ? "":<Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@9i60af`} title="未查看目标"><span className="workrelate-unread">{unread.specialGoal}</span></Tooltip>}</Item>
            <Item ecId={`${this && this.props && this.props.ecId || ''}_Item@idks2f`} key="5" style={{height:'30px',lineHeight:"30px"}} title={getLabel(506159,"分享给我的目标")}><span>{getLabel(506159,"分享给我的目标")}</span>{unread.shareGoal == 0 ? "":<Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@98r4zq`} title="未查看目标"><span className="workrelate-unread">{unread.shareGoal}</span></Tooltip>}</Item>
            <Item ecId={`${this && this.props && this.props.ecId || ''}_Item@10x6pl`} key="0" style={{height:'30px',lineHeight:"30px"}} title={getLabel(506160,"所有目标")}><span>{getLabel(506160,"所有目标")}</span>{unread.allGoal == 0 ?  "":<Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@yjwmos`} title="未查看目标"><span className="workrelate-unread">{unread.allGoal}</span></Tooltip>}</Item>
            <Item ecId={`${this && this.props && this.props.ecId || ''}_Item@f20zlb`} key="10" style={{height:'30px',lineHeight:"30px"}} title={getLabel(520928,"目标导出")}><span>{getLabel(520928,"目标导出")}</span>{unread.allGoal == 0 ?  "":<Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@rmxhrz`} title="未查看目标"><span className="workrelate-unread">{unread.allGoal}</span></Tooltip>}</Item>
            {/* <Item key="7" style={{height:'30px',lineHeight:"30px"}} title={getLabel(518141,"组织目标")}><span>{getLabel(518141,"组织目标")}</span>{unread.allGoal == 0 ?  "":<Tooltip title="未查看目标"><span className="workrelate-unread">{unread.allGoal}</span></Tooltip>}</Item> */}
        </Menu>;
        return (
            <div className="wea-workrelate-goal-menu wea-workrelate-common-menu">
                <WeaLeftRightLayout ecId={`${this && this.props && this.props.ecId || ''}_WeaLeftRightLayout@zx5x3y`}
                    leftCom={<div className="common-menu-title">{menu}</div>}
                    leftWidth={248}
                    onCollapse={showLeft =>{}}>
                    <div>{cunrrentkey == 10 ? <GoalExport ecId={`${this && this.props && this.props.ecId || ''}_GoalExport@4df149`}></GoalExport>:<GoalMain ecId={`${this && this.props && this.props.ecId || ''}_GoalMain@ndbnod`} condtype={cunrrentkey} menuid={cunrrentkey} toptitle={toptitle} onRef={this.onRef} />}</div>
                </WeaLeftRightLayout>
            </div>
        )
    }
};